# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=rnp
pkgver=0.15.2
pkgrel=3
pkgdesc="High performance C++ OpenPGP library used by Mozilla Thunderbird"
url="https://www.rnpgp.org/"
arch="all"
license="BSD-2-Clause"
checkdepends="gnupg gtest-dev"
makedepends="
	asciidoctor
	botan-dev
	bzip2-dev
	cmake
	json-c-dev
	zlib-dev
	"
subpackages="$pkgname-dev $pkgname-doc librnp"
source="https://github.com/rnpgp/rnp/archive/v$pkgver/rnp-$pkgver.tar.gz
	fix-test_rnpkeys_lists.patch
	avoid-testing-chunk-sizes-greater-than-16.patch
	cleanup-nopermsdir.patch
	disable-obsolete-ciphers.patch
	"

case "$CARCH" in
	# FIXME: one test fails
	s390x) options="!check";;
esac

build() {
	# Avoid polluting /tmp.
	export TEMP="$builddir/.tmp"
	mkdir -p "$TEMP"

	local crossopts=
	if [ "$CBUILD" != "$CHOST" ]; then
		crossopts="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	# CMAKE_INTERPROCEDURAL_OPTIMIZATION - enable LTO
	cmake -B build \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DCMAKE_VERBOSE_MAKEFILE=ON \
		-DBUILD_SHARED_LIBS=ON \
		-DBUILD_TESTING=$(want_check && echo ON || echo OFF) \
		-DDOWNLOAD_GTEST=OFF \
		-DDOWNLOAD_RUBYRNP=OFF \
		-DGIT_EXECUTABLE=/bin/false \
		$crossopts .
	cmake --build build
}

check() {
	cd build
	CTEST_OUTPUT_ON_FAILURE=TRUE ctest -j4
}

package() {
	pkgdesc="$pkgdesc (CLI tools)"

	DESTDIR="$pkgdir" cmake --install build
}

librnp() {
	default_libs
}

sha512sums="
ba2f3252443b1e3e9069afc2704e2fb64514f423cd5b4db18130de2c90d1ab9f116596138037e4b054410a7003789b395fa0a7347b273be12bfe557ce79fde2c  rnp-0.15.2.tar.gz
ec2695424427dc4178b55372dda7236cf477c3dab64d80f9a6bd7b1da434f71bab6c9c2fcbc5134e2255fc76d35ef708fa57d706a5c9bfbc21274ab48a416909  fix-test_rnpkeys_lists.patch
04004950044cef0e67cad8a88c641cea8aab7f07cdd188a83df067f0e1a639c58ecf42ded89f1f9f542ad08876f19e6387a32d3293ce3fcfca152fbe017baad5  avoid-testing-chunk-sizes-greater-than-16.patch
abb84713d54763b5cfb4a3a80078db04ef3ad7c8913bfdcc44c82081e1d4547039e78cfaae8a11ead53e05bc7f9308641c044a62c8fe9f8c4922b12495c61240  cleanup-nopermsdir.patch
585acdf6075578c403430470e79e48e5901f36e598ded9c82b2f079b0870dfbdb803dc63753f103137bc5eef399a2586b668c4bbbaf93877a21e3315c0d421df  disable-obsolete-ciphers.patch
"
